package com.fa.service.impl;

import com.fa.common.utils.SecurityUtils;
import com.fa.domain.Location;
import com.fa.domain.LocationSearchVO;
import com.fa.domain.LocationVO;
import com.fa.mapper.LocationMapper;
import com.fa.service.LocationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.List;

@Service
public class LocationServiceImpl implements LocationService {

    @Autowired
    private LocationMapper locationMapper;
    @Override
    public List<LocationVO> listLocation(LocationSearchVO locationSearchVO) {
        List<LocationVO> locationVOS = locationMapper.listLocation(locationSearchVO);
        return locationVOS;
    }

    @Override
    public void addLocationList(List<Location> locationList) {
        String username = SecurityUtils.getUsername();
        Date date = new Date();
        for (Location location : locationList) {
            location.setCreateBy(username);
            location.setCreateTime(date);
        }
        locationMapper.addLocationList(locationList);
    }

    @Override
    public void delLocationList(List<Integer> locationIds) {
        locationMapper.delLocationList(locationIds);
    }

    @Override
    public void updateLocation(Location location) {
        String username = SecurityUtils.getUsername();
        location.setUpdateBy(username);
        location.setUpdateTime(new Date());
        locationMapper.updateLocation(location);
    }

    @Override
    public LocationVO listLocationById(Long locationId) {
        LocationVO locationVO = locationMapper.listLocationById(locationId);
        return locationVO;
    }
}
